<?php
/**
 * View Nuovo Contatto - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    16-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
//<![CDATA[
    $(document).ready(function() {

        validator.groups = {contact_firstname: "contact_name", contact_lastname: "contact_name", 
                            contact_phone_prefix: "contact_phone", contact_phone_number: "contact_phone", 
                            contact_work_prefix: "contact_work", contact_work_number: "contact_work", 
                            contact_mobile_prefix: "contact_mobile", contact_mobile_prefix: "contact_mobile", 
                            contact_fax_prefix: "contact_fax", contact_fax_prefix: "contact_fax", 
                            contact_street: "address", contact_city: "address", contact_province_id: "address"
                            }
                            
        $("#contact_firstname").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#contact_lastname").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#contact_email").rules("add", {
            required: true,
            email: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>",
                email: "<?php echo ERR_EMAIL ?>"
            }
        });

        $("#contact_phone_prefix").rules("add", {
            required: true,
            digits: true,
            rangelength: [1, 4],
            messages: {
                required: "<?php echo ERR_EMPTY ?>",
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Principale' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Principale' )?>"
            }
        });

        $("#contact_phone_number").rules("add", {
            required: true,
            digits: true,
            rangelength: [1, 10],
            messages: {
                required: "<?php echo ERR_EMPTY ?>",
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Principale' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Principale' )?>"
            }
        });

        $("#contact_email2").rules("add", {
            email: true,
            messages: {
                email: "<?php echo ERR_EMAIL ?>"
            }
        });

        $("#contact_email3").rules("add", {
            email: true,
            messages: {
                email: "<?php echo ERR_EMAIL ?>"
            }
        });

        $("#contact_work_prefix").rules("add", {
            digits: true,
            rangelength: [1, 4],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Lavoro' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Lavoro' )?>"
            }
        });

        $("#contact_work_number").rules("add", {
            digits: true,
            rangelength: [1, 10],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Lavoro' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Lavoro' )?>"
            }
        });       

        $("#contact_mobile_prefix").rules("add", {
            digits: true,
            rangelength: [1, 4],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Privato' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Privato' )?>"
            }
        });

        $("#contact_mobile_number").rules("add", {
            digits: true,
            rangelength: [1, 10],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Privato' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Tel. Privato' )?>"
            }
        });       

        $("#contact_fax_prefix").rules("add", {
            digits: true,
            rangelength: [1, 4],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Fax' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Fax' )?>"
            }
        });

        $("#contact_fax_number").rules("add", {
            digits: true,
            rangelength: [1, 10],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'Fax' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'Fax' )?>"
            }
        });       
        
        $("#contact_cap").rules("add", {
            digits: true,
            rangelength: [5, 5],
            range: [0, 98100],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                range : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>"
            }
        });
        
        $("#contact_city").rules("add", {
            required: {
                depends: function(element) {
                    return ($('#contact_street').val() != '' || 
                            $('#contact_street_number').val() != '' );
                }
            },
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#contact_province_id").rules("add", {
            required: {
                depends: function(element) {
                    return ($('#contact_street').val() != '' || 
                            $('#contact_street_number').val() != '' ||
                            $('#contact_city').val() != '');
                }
            },
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });        

    });

    //]]>
</script>

<div class="info">
    <h2>Gestisci Contatti</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>

<form class="fab" name="contactForm" id="contactForm" action="/admin/contatti/info/id/<?php echo $this->contact_id ?>" method="post">
    <ul>
	<li class="paging-context ">
	    <table class="pgStyle1 circle2" cellspacing="0">
		<tr>
		    <td class="c selected">
			<var>1</var>
		    </td>
		    <td class="t selected">
			<b id="pagecircle1">Dettagli Contatto</b>
		    </td>
		    <td class="c ">
			<var>2</var>
		    </td>
		    <td class="t">
			<b id="pagecircle2">Associa Contatto</b>
		    </td>
		</tr>
	    </table>
	</li>
    </ul>
<div id="content">   
    <ul>
	<li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none'?>">
	    <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
	    <p id="errorMsg">
		Di seguito trovi evidenziati gli errori riscontrati.
	    </p>
	</li>
	<li class="<?php echo $this->errorMsg['contact_firstname'] ? 'error' : '' ?>">
	    <div class="float-left">
		<label class="desc <?php echo $this->errorMsg['contact_firstname'] ? 'error' : '' ?>">Nome<span class="req">*</span></label>
		<span class="input">
		    <input id="contact_firstname" name="contact_firstname" class="field text" size="20" type="text" maxlength="255" value="<?php echo $this->data['contact_firstname'] ?>" />
		    <label>Nome</label>
		</span>
		    
		<span class="input">
		    <input id="contact_lastname" name="contact_lastname" class="field text" size="20" type="text" maxlength="255" value="<?php echo $this->data['contact_lastname'] ?>" />
		    <label>Cognome</label>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_name'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['contact_name'] ?></p>
	</li>

	<li class="<?php echo $this->errorMsg['contact_email'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_email'] ? 'error' : ''?>">Email Principale<span class="req">*</span></label>
	    <div>
		<span>
		    <input id="contact_email" name="contact_email" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['contact_email']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_email'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_email']?></p>
	</li>
	
	<li class="<?php echo $this->errorMsg['contact_phone'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_phone'] ? 'error' : ''?>">Tel. Principale<span class="req">*</span></label>
	    <div class="float-left">
		<span class="input">
		    <input class="field text" id="contact_phone_prefix" name="contact_phone_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['contact_phone_prefix']?>" /> / 
		    <label>Pref</label>
		</span>

		<span class="input">
		    <input class="field text" id="contact_phone_number" name="contact_phone_number" type="text" size="10" value="<?php echo $this->data['contact_phone_number']?>" /> 
		    <label>Numero</label>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_phone'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_phone']?></p>
	</li>
	
	<li class="section">
	    <h3>Altre Informazioni di Contatto</h3>
	    <div id="instruct3">Inserisci le informazioni facoltative del contatto</div>
	</li>
	
	<li class="<?php echo $this->errorMsg['contact_email2'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_email2'] ? 'error' : ''?>">Email 2</label>
	    <div>
		<span>
		    <input id="contact_email2" name="contact_email2" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['contact_email2']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_email2'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_email2']?></p>
	</li>
	
	<li class="<?php echo $this->errorMsg['contact_email3'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_email3'] ? 'error' : ''?>">Email 3</label>
	    <div>
		<span>
		    <input id="contact_email3" name="contact_email3" class="field text medium" type="text" maxlength="255" value="<?php echo $this->data['contact_email3']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_email3'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_email3']?></p>
	</li>	
	
	<li class="<?php echo $this->errorMsg['contact_work'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_work'] ? 'error' : ''?>">Tel. Lavoro</label>
	    <div class="float-left">
		<span class="input">
		    <input class="field text" id="contact_work_prefix" name="contact_work_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['contact_work_prefix']?>" /> / 
		    <label>Pref</label>
		</span>

		<span class="input">
		    <input class="field text" id="contact_work_number" name="contact_work_number" type="text" size="10" value="<?php echo $this->data['contact_work_number']?>" /> 
		    <label>Numero</label>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_work'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_work']?></p>
	</li>
	
	<li class="<?php echo $this->errorMsg['contact_mobile'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_mobile'] ? 'error' : ''?>">Tel. Privato</label>
	    <div class="float-left">
		<span class="input">
		    <input class="field text" id="contact_mobile_prefix" name="contact_mobile_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['contact_mobile_prefix']?>" /> / 
		    <label>Pref</label>
		</span>

		<span class="input">
		    <input class="field text" id="contact_mobile_number" name="contact_mobile_number" type="text" size="10" value="<?php echo $this->data['contact_mobile_number']?>" /> 
		    <label>Numero</label>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_mobile'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_mobile']?></p>
	</li>

	<li class="<?php echo $this->errorMsg['contact_fax'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_fax'] ? 'error' : ''?>">Fax</label>
	    <div class="float-left">
		<span class="input">
		    <input class="field text" id="contact_fax_prefix" name="contact_fax_prefix" type="text" size="4" maxlength="4" value="<?php echo $this->data['contact_fax_prefix']?>" /> / 
		    <label>Pref</label>
		</span>

		<span class="input">
		    <input class="field text" id="contact_fax_number" name="contact_fax_number" type="text" size="10" value="<?php echo $this->data['contact_fax_number']?>" /> 
		    <label>Numero</label>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_fax'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_fax']?></p>
	</li>

	<li class="section">
	    <h3>Altre Info</h3>
	</li>
	
	<li class="complex <?php echo $this->errorMsg['contact_address'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_address'] ? 'error' : ''?>">Indirizzo</label>
	    <div>
		<span class="input">
		    <input class="field text addr" name="contact_street" id="contact_street" size="50" type="text" value="<?php echo $this->data['contact_street']?>" />
		    <label>Via</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="contact_street_number" id="contact_street_number" size="2" type="text" value="<?php echo $this->data['contact_street_number']?>" />
		    <label>N&deg;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="contact_loc" id="contact_loc" size="50" type="text" value="<?php echo $this->data['contact_loc']?>" />
		    <label>Localit&aacute;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="contact_city" id="contact_city" size="50" type="text" value="<?php echo $this->data['contact_city']?>" />
		    <label>Citt&aacute;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="contact_cap" id="contact_cap" size="10" type="text" value="<?php echo $this->data['contact_cap']?>" />
		    <label>CAP</label>
		</span>

		<span class="left">
		    <select class="field select addr" name="contact_province_id" id="contact_province_id">
			<option value="">-- Seleziona la provincia --</option>
			<?php foreach( $this->province AS $k => $provincia ): ?>
			<option value="<?php echo $k?>" <?php echo ( $this->data['contact_province_id'] == $k ) ? 'selected="selected"' : ''?>><?php echo $provincia['province_long_name']?></option>
			<?php endforeach; ?>
		    </select>
		    <label>Provincia</label>
		</span>
		<p class="error" style="<?php echo $this->errorMsg['contact_address'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_address']?></p>
	    </div>
	</li>
	
	<li class="section">
	    <h3></h3>
	</li>	
	
	<li class="<?php echo $this->errorMsg['contact_notes'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['contact_notes'] ? 'error' : ''?>">Note</label>
	    <div>
		<span>
		    <textarea id="contact_notes" class="field textarea small" name="contact_notes" rows="3" cols="100"><?php echo htmlentities( $this->data['contact_notes'] ) ?></textarea>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['contact_notes'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['contact_notes']?></p>
	</li>

    </ul>
</div>
    <div id="formButtons">
        <button id="salva" type="submit" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <button id="annulla" name="annulla" value="annulla" class="button negative">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </button>
    </div>
</form>
